<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List Products</title>
</head>
<body>
<center>
	<h1>Product Compare Application</h1>
	<button id="List" onclick="window.location.href='admin_ListProducts.jsp'">Get Product List</button>
	<button id="AddProduct" onclick="window.location.href='admin_AddProduct.jsp'">Add New Product</button>
	<button id="AddSuperMarket" onclick="window.location.href='admin_AddSupermarket.jsp'">Add New SuperMarket</button>
	<button id="ManageSuperMarket" onclick="window.location.href='admin_ManageSupermarket.jsp'">Manage Supermarket</button>
	<button id="DeleteProduct" onclick="window.location.href='admin_DeleteProduct.jsp'">Delete Product</button>
	<button id="DeleteSupermarket" onclick="window.location.href='admin_DeleteSupermarket.jsp'">Delete Supermarket</button>
</center>
<center>
<br><br>
<%
	try
	{
		List<Product> products = iproducts.FindAllProducts();
		for (Product product : products)
		{
			out.println("<table border=1><tr bgcolor=\"grey\"><tr colspan=4>" + product.getProductName() + "</th></tr>");
			out.println("<tr bgcolor=\"grey\"><th>Product Unit</th><td>" + product.getProductUnit() + "</td>");
			out.println("<th>Unit Quantity</th><td>" + product.getProductQuantityPerUnit().toString() + "</td></tr>");
			Set<ProductSupermarket> productSupermarkets = iproducts.FindAllProductSupermarkets(product);
			out.println("<tr bgcolor=\"grey\"><th>SuperMarket</th><th>Price</th><th>Unit</th><th>Quantity Per Unit</th></tr>");
			for (Iterator<ProductSupermarket> iterPS = productSupermarkets.iterator(); iterPS.hasNext();)
			{
				ProductSupermarket productSupermarket = (ProductSupermarket) iterPS.next();
				out.println("<tr><td>" + productSupermarket.getSupermarket().getSupermarketName() + "</td>");
				out.println("<td>" + productSupermarket.getPrice() + "</td>");
				out.println("</tr>");
			}
			out.println("</table><br>");
		}
	}
	catch (Exception e)
	{
	    throw new Exception("Error in connecting to database, please contact your administrator");
	}
%>
</center>
</body>
</html>